//
//  XMGHallTableViewController.m
//  小码哥彩票
//
//  Created by simplyou on 15/11/10.
//  Copyright © 2015年 simplyou. All rights reserved.
//
#define UISCREENHEIGHT  self.view.bounds.size.height
#define UISCREENWIDTH  self.view.bounds.size.width
#import "XMGHallTableViewController.h"
#import "UIImage+XMG.h"
#import "XMGCover.h"
#import "XMGPopMenu.h"
#import "UIView+XMG.h"
#import "AdScrollView.h"
#import "AdDataModel.h"
#import "BJhomeTableViewCell.h"
@interface XMGHallTableViewController ()<XMGPopMenuDelegate,UITableViewDelegate,UITableViewDataSource>
{
    AdScrollView * _scrollView;
    UITableView* _tableView;
}
@end

@implementation XMGHallTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initScorllView];
    [self initTableView];
    // 在iOS7以后导航控制器上得图片默认是渲染的
    // 设置image 呈现方式
//   UIImage *image = [UIImage imageNamed:@"CS50_activity_image"];
//   image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    [UIImage imageWithOriginal:<#(NSString *)#>]
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginal:@"CS50_activity_image"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarOnClick)];
}

-(void)initTableView
{
    UITableView* tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    tableView.frame = CGRectMake(0, CGRectGetMaxY(_scrollView.frame),UISCREENWIDTH,self.view.frame.size.height - CGRectGetMaxY(_scrollView.frame) - 55 - 50);
    _tableView = tableView;
//    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}


-(void)initScorllView
{
    AdScrollView * scrollView = [[AdScrollView alloc]initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, 150)];
    _scrollView = scrollView;
    AdDataModel * dataModel = [AdDataModel adDataModelWithImageNameAndAdTitleArray];

    scrollView.imageNameArray = dataModel.imageNameArray;
    scrollView.PageControlShowStyle = UIPageControlShowStyleRight;
    scrollView.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
    
    [scrollView setAdTitleArray:dataModel.adTitleArray withShowStyle:AdTitleShowStyleLeft];
    
    scrollView.pageControl.currentPageIndicatorTintColor = [UIColor purpleColor];
    [self.view addSubview:scrollView];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

-(BJhomeTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier = @"bjHomeTBCell";
    BJhomeTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"BJhomeTableViewCell" owner:nil options:0]firstObject];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

// 当导航条左侧按钮点击就会调用
- (void)leftBarOnClick{
    // 蒙版一般加载窗口上
    // 弹出蒙版,
    [XMGCover show];

    // 创建pop菜单
    XMGPopMenu *popMenu = [XMGPopMenu showInCenter:self.view.center];
    popMenu.delegae = self;
    
}
#pragma mark - XMGPopMenuDelegate
- (void)popMenudDidColseBtn:(XMGPopMenu *)popMenu{
    
//    [UIView animateWithDuration:0 animations:nil completion:^(BOOL finished) {
//        
//    }];
    
    // 封装菜单动画执行完毕的时候调用的代码
    void (^completion)() = ^{
        // 当菜单的动画执行完毕的时候,隐藏蒙版
        [XMGCover hidden];
    };
    
    // block精髓: 当参数传递
    // 关闭菜单
    [popMenu hiddenInCenter:CGPointMake(44, 44) completion:completion];
    
    // 关闭菜单
//    [popMenu hiddenInCenter:CGPointMake(44, 44) completion:^{
//    
//    }];
    
    
    
}
@end
